package com.intramirror.product.utils;

import com.intramirror.product.entity.Spu;
import com.intramirror.product.entity.SpuExceptionProduct;
import com.intramirror.product.entity.SpuOperateLog;
import com.intramirror.utils.transform.JsonTransformUtil;
import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2018/4/27.
 * @author 123
 */
public class SpuLogUtil {

    public static final Integer REMOVE_PRODUCT_FROM_SPU = 1;
    public static final Integer UPDATE_SPU = 2;

    public static SpuOperateLog buildSpuExceptionProduct(Long userId, SpuExceptionProduct spuExceptionProduct) {
        SpuOperateLog log = new SpuOperateLog();
        log.setType(REMOVE_PRODUCT_FROM_SPU);
        log.setDescription("Remove from spu.");
        log.setSpuId(spuExceptionProduct.getSpuId());
        log.setProductId(spuExceptionProduct.getProductId());
        log.setUserId(userId);
        log.setContent(JsonTransformUtil.toJson(spuExceptionProduct));
        return log;
    }

    public static SpuOperateLog buildSaveSpuLog(Long userId, Spu old, Spu newPpu) {
        SpuOperateLog log = new SpuOperateLog();
        log.setType(UPDATE_SPU);
        log.setDescription("Update spu.");
        log.setSpuId(old.getSpuId());
        log.setUserId(userId);

        List<Spu> content = new ArrayList<>();
        content.add(old);
        content.add(newPpu);
        log.setContent(JsonTransformUtil.toJson(content));
        return log;
    }
}
